<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style>
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
    margin: 0;
    padding: 0;
}
body {
    font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
    font-size: 13px;
    line-height: 18px;
    color: #737373;
    background-color: white;
    margin: 10px 13px 10px 13px;
}
table {
	margin: 10px 0 15px 0;
	border-collapse: collapse;
}
td,th {	
	border: 1px solid #ddd;
	padding: 3px 10px;
}
th {
	padding: 5px 10px;	
}

a {
    color: #0069d6;
}
a:hover {
    color: #0050a3;
    text-decoration: none;
}
a img {
    border: none;
}
p {
    margin-bottom: 9px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
    color: #404040;
    line-height: 36px;
}
h1 {
    margin-bottom: 18px;
    font-size: 30px;
}
h2 {
    font-size: 24px;
}
h3 {
    font-size: 18px;
}
h4 {
    font-size: 16px;
}
h5 {
    font-size: 14px;
}
h6 {
    font-size: 13px;
}
hr {
    margin: 0 0 19px;
    border: 0;
    border-bottom: 1px solid #ccc;
}
blockquote {
    padding: 13px 13px 21px 15px;
    margin-bottom: 18px;
    font-family:georgia,serif;
    font-style: italic;
}
blockquote:before {
    content:"\201C";
    font-size:40px;
    margin-left:-10px;
    font-family:georgia,serif;
    color:#eee;
}
blockquote p {
    font-size: 14px;
    font-weight: 300;
    line-height: 18px;
    margin-bottom: 0;
    font-style: italic;
}
code, pre {
    font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
    background-color: #fee9cc;
    color: rgba(0, 0, 0, 0.75);
    padding: 1px 3px;
    font-size: 12px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
}
pre {
    display: block;
    padding: 14px;
    margin: 0 0 18px;
    line-height: 16px;
    font-size: 11px;
    border: 1px solid #d9d9d9;
    white-space: pre-wrap;
    word-wrap: break-word;
}
pre code {
    background-color: #fff;
    color:#737373;
    font-size: 11px;
    padding: 0;
}
sup {
    font-size: 0.83em;
    vertical-align: super;
    line-height: 0;
}
* {
	-webkit-print-color-adjust: exact;
}
@media screen and (min-width: 914px) {
    body {
        width: 854px;
        margin:10px auto;
    }
}
@media print {
	body,code,pre code,h1,h2,h3,h4,h5,h6 {
		color: black;
	}
	table, pre {
		page-break-inside: avoid;
	}
}
</style>
<title>jetty多实例部署</title>

</head>
<body>
<h1>jetty多实例部署</h1>

<hr />

<h2>jdk环境部署</h2>

<p>下载jdk部署环境变量，这里不再介绍。</p>

<h2>下载jetty</h2>

<pre><code>wget http://mirror.neu.edu.cn/eclipse/jetty/stable-9/dist/jetty-distribution-9.2.10.v20150310.tar.gz   
tar zxvf jetty-distribution-9.2.10.v20150310.tar.gz -C /opt/
</code></pre>

<h2>配置</h2>

<pre><code>cd /opt/jetty-distribution-9.2.10.v20150310
cp start.ini start.ini.bak
vi start.ini
</code></pre>

<p>删除或者注释掉端口相关信息</p>

<pre><code>--module=server
threads.min=10
threads.max=200
threads.timeout=60000
jetty.output.buffer.size=32768
jetty.request.header.size=8192
jetty.response.header.size=8192
jetty.send.server.version=true
jetty.send.date.header=false
jetty.dump.start=false
jetty.dump.stop=false
jetty.delayDispatchUntilContent=false

--module=deploy
--module=ext
--module=resources
--module=jsp
--module=jstl
http.timeout=30000
</code></pre>

<p>修改<code>./etc/jetty-deploy.xml</code></p>

<pre><code>&lt;Set name="monitoredDirName"&gt;&lt;Property name="jetty.base" default="." /&gt;/&lt;Property name="jetty.deploy.monitoredDirName" default="webapps"/&gt;&lt;/Set&gt;
</code></pre>

<p>修改后为</p>

<pre><code>&lt;Set name="monitoredDirName"&gt;&lt;Property name="jetty.appHome" default="" /&gt;/conf&lt;/Set&gt;
</code></pre>

<p>修改<code>modules/http.mod</code>文件，注释掉端口信息<code>jetty.port=8080</code></p>

<p>应用部署结构</p>

<pre><code>[root@ljl app]# tree
.
├── conf
│   ├── ROOT.xml
│   └── _run.sh
├── logs
├── restart.sh
└── webapps   
</code></pre>

<p>ROOT.xml 文件内容</p>

<pre><code>[root@ljl conf]# cat ROOT.xml
&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"&gt;
&lt;!-- =============================================================== --&gt;
&lt;!-- Configure the weibo-api webapp                           --&gt;
&lt;!-- =============================================================== --&gt;
&lt;Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;!-- =============================================================== --&gt;
&lt;!-- Configure the webapp                                            --&gt;
&lt;!-- =============================================================== --&gt;
&lt;Set name="contextPath"&gt;/&lt;/Set&gt;
&lt;Set name="war"&gt;&lt;SystemProperty name="jetty.appHome"/&gt;/webapp&lt;/Set&gt;
&lt;Set name="extractWAR"&gt;false&lt;/Set&gt;
&lt;Set name="copyWebDir"&gt;false&lt;/Set&gt;
&lt;Set name="configurationDiscovered"&gt;true&lt;/Set&gt;
&lt;/Configure&gt;   
</code></pre>

<p>_run.sh 文件内容</p>

<pre><code>[root@ljl conf]# cat _run.sh
#!/bin/bash

APP_HOME=$(cd "$(dirname "$0")/.."; pwd )
export JETTY_LOGS=$APP_HOME/logs/$JETTY_PORT
mkdir -p $JETTY_LOGS
export JAVA_OPTIONS="$JAVA_OPTIONS  -Djetty.appHome=$APP_HOME -Djetty.port=$JETTY_PORT"
$JETTY_HOME/bin/jetty.sh $1   
</code></pre>

<p>restart.sh文件内容</p>

<pre><code>[root@ljl app]# cat restart.sh
#!/bin/bash
#####################################################
cd `dirname $0`
jetty(){
    export JETTY_PORT=$1
    ./conf/_run.sh stop
    sleep 2
    echo "Start Jetty On port $1.."
    ./conf/_run.sh start &amp;&gt;logs/jetty.log
    sleep 4
}
#####################################################
export JETTY_HOME=/opt/jetty
export JAVA_OPTIONS="-Xms2g -Xmx2g"
# -Dorg.eclipse.jetty.util.URI.charset=UTF-8"
jetty 9092

#IP=`ifconfig $1|sed -n 2p|awk  '{ print $2 }'|awk -F : '{ print $2 }'`
#echo $IP &gt;&gt; webapp/index.html
echo "$IP done.."    
</code></pre>

<p>项目放在webapps目录启动即可。</p>
</body>
</html>